<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rust学习智能体 - 问答与可视化</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet">
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
    <style>
        body {
            background-color: #fff3e0;
            background-image: 
                radial-gradient(circle at 10% 20%, rgba(206, 66, 43, 0.05) 0%, transparent 50%),
                radial-gradient(circle at 80% 80%, rgba(247, 76, 0, 0.07) 0%, transparent 50%),
                radial-gradient(circle at 40% 40%, rgba(255, 152, 0, 0.05) 0%, transparent 50%);
        }
        
        /* 通知样式 */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 20px;
            border-radius: 8px;
            color: white;
            font-weight: 500;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            z-index: 9999;
            transform: translateX(120%);
            transition: transform 0.3s ease, opacity 0.3s ease;
            max-width: 300px;
        }
        
        .notification.show {
            transform: translateX(0);
            opacity: 1;
        }
        
        .notification-success {
            background: linear-gradient(135deg, #28a745, #20c997);
        }
        
        .notification-error {
            background: linear-gradient(135deg, #dc3545, #e74c3c);
        }
        
        .notification-info {
            background: linear-gradient(135deg, #17a2b8, #3498db);
        }
        
        /* 加载动画 */
        .loading-spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s ease-in-out infinite;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        /* 挑战卡片动画 */
        .challenge-card {
            transition: all 0.3s ease;
            transform-style: preserve-3d;
            position: relative;
        }
        
        .challenge-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        
        .challenge-card.completed {
            position: relative;
            overflow: hidden;
        }
        
        .challenge-card.completed::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(135deg, rgba(40, 167, 69, 0.1), rgba(32, 201, 151, 0.1));
            pointer-events: none;
        }
        
        /* 拖拽区域样式 */
        .drop-zone {
            border: 2px dashed #ce422b;
            border-radius: 8px;
            padding: 20px;
            margin: 10px 0;
            background-color: rgba(206, 66, 43, 0.05);
            transition: all 0.3s ease;
            min-height: 60px;
        }
        
        .drop-zone.drag-over {
            background-color: rgba(206, 66, 43, 0.1);
            border-color: #a73420;
            transform: scale(1.02);
        }
        
        /* 代码片段样式 */
        .code-snippet {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
            border-radius: 6px;
            padding: 10px;
            margin: 5px;
            cursor: move;
            transition: all 0.3s ease;
            font-family: 'Courier New', monospace;
            font-size: 14px;
            display: inline-block;
        }
        
        .code-snippet:hover {
            background-color: #e9ecef;
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .code-snippet.dragging {
            opacity: 0.5;
            transform: rotate(5deg);
        }
        
        /* 响应式调整 */
        @media (max-width: 768px) {
            .sidebar {
                position: fixed;
                top: 0;
                left: -280px;
                height: 100vh;
                z-index: 1001;
                transition: left 0.3s ease;
            }
            
            .sidebar.active {
                left: 0;
            }
            
            .mobile-menu-toggle {
                display: block !important;
            }
            
            .main-content {
                margin-left: 0;
            }
            
            .tab-button {
                font-size: 0.875rem;
                padding: 0.6rem 0.5rem;
            }
            
            .tab-button i {
                margin-right: 0.25rem;
            }
        }
        
        /* 动画效果 */
        .animate-on-scroll {
            opacity: 0;
            transform: translateY(20px);
            transition: opacity 0.5s ease, transform 0.5s ease;
        }
        
        .animate-on-scroll.animated {
            opacity: 1;
            transform: translateY(0);
        }
    </style>
</head>
<body>
    <div class="app-container">
        <header class="app-header">
            <div class="d-flex justify-content-between align-items-center">
                <div class="d-flex align-items-center">
                    <button class="mobile-menu-toggle me-3">
                        <i class="fas fa-bars"></i>
                    </button>
                    <h1 class="h3 mb-0">
                        <i class="fas fa-cog me-2"></i>
                        Rust学习智能体
                    </h1>
                </div>
                <div>
                    <span class="badge bg-light text-dark me-2">
                        <i class="fas fa-circle text-success me-1"></i>
                        星河大模型
                    </span>
                </div>
            </div>
        </header>

        <div class="app-content">
            <aside class="sidebar" id="sidebar">
                <div class="mb-4">
                    <h5 class="mb-3">
                        <i class="fas fa-book me-2"></i>
                        Rust知识点
                    </h5>
                    <div class="knowledge-card" data-topic="ownership">
                        <h5>所有权系统</h5>
                        <p>Rust的核心内存管理机制</p>
                    </div>
                    <div class="knowledge-card" data-topic="borrowing">
                        <h5>借用检查器</h5>
                        <p>确保内存安全的引用机制</p>
                    </div>
                    <div class="knowledge-card" data-topic="lifetimes">
                        <h5>生命周期</h5>
                        <p>管理引用有效性的机制</p>
                    </div>
                    <div class="knowledge-card" data-topic="traits">
                        <h5>Trait系统</h5>
                        <p>Rust的多态和代码共享机制</p>
                    </div>
                    <div class="knowledge-card" data-topic="error-handling">
                        <h5>错误处理</h5>
                        <p>Result和Option类型的使用</p>
                    </div>
                    <div class="knowledge-card" data-topic="concurrency">
                        <h5>并发编程</h5>
                        <p>线程、通道和同步原语</p>
                    </div>
                    <div class="knowledge-card" data-topic="macros">
                        <h5>宏系统</h5>
                        <p>元编程和代码生成</p>
                    </div>
                    <div class="knowledge-card" data-topic="async">
                        <h5>异步编程</h5>
                        <p>Future、async/await模式</p>
                    </div>
                </div>

                <div class="mt-4">
                    <h5 class="mb-3">
                        <i class="fas fa-question-circle me-2"></i>
                        常见问题
                    </h5>
                    <div class="list-group">
                        <a href="#" class="list-group-item list-group-item-action sidebar-question">
                            Rust的所有权是什么？
                        </a>
                        <a href="#" class="list-group-item list-group-item-action sidebar-question">
                            如何使用Vec？
                        </a>
                        <a href="#" class="list-group-item list-group-item-action sidebar-question">
                            生命周期是什么？
                        </a>
                        <a href="#" class="list-group-item list-group-item-action sidebar-question">
                            如何处理错误？
                        </a>
                    </div>
                </div>
            </aside>

            <main class="main-content">
                <div class="tab-container">
                    <button class="tab-button active" data-tab="chat">
                        <i class="fas fa-comments me-2"></i>
                        <span>智能问答</span>
                    </button>
                    <button class="tab-button" data-tab="visualization">
                        <i class="fas fa-project-diagram me-2"></i>
                        <span>知识可视化</span>
                    </button>
                    <button class="tab-button" onclick="window.location.href='/challenges'">
                        <i class="fas fa-gamepad me-2"></i>
                        <span>代码闯关</span>
                    </button>
                </div>

                <div class="tab-content active" id="chat-tab">
                    <div class="chat-container">
                        <div class="chat-welcome" id="chat-welcome">
                            <div class="welcome-icon">
                                <i class="fas fa-comments"></i>
                            </div>
                            <h3>欢迎使用Rust学习智能体</h3>
                            <p>我是基于星河大模型的专业Rust学习助手，可以回答您的任何Rust相关问题</p>
                            <div class="suggested-questions">
                                <h5>试试这些问题：</h5>
                                <div class="question-suggestions">
                                    <button class="suggestion-btn" data-question="Rust的所有权系统是如何工作的？">
                                        <i class="fas fa-question-circle me-2"></i>
                                        Rust的所有权系统是如何工作的？
                                    </button>
                                    <button class="suggestion-btn" data-question="如何在Rust中处理错误？">
                                        <i class="fas fa-exclamation-triangle me-2"></i>
                                        如何在Rust中处理错误？
                                    </button>
                                    <button class="suggestion-btn" data-question="Rust中的生命周期是什么？">
                                        <i class="fas fa-clock me-2"></i>
                                        Rust中的生命周期是什么？
                                    </button>
                                    <button class="suggestion-btn" data-question="如何使用Rust的异步编程？">
                                        <i class="fas fa-sync me-2"></i>
                                        如何使用Rust的异步编程？
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="messages-container" id="messages-container" style="display: none;">
                            <!-- Messages will be dynamically inserted here -->
                        </div>
                        <div class="input-area">
                            <div class="input-container">
                                <textarea class="message-input" id="message-input" placeholder="输入你的问题..." rows="1"></textarea>
                                <button class="send-btn" id="send-button">
                                    <i class="fas fa-paper-plane"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-content" id="visualization-tab">
                    <div class="visualization-container">
                        <div class="topic-selector">
                            <h5 class="mb-3">
                                <i class="fas fa-chart-line me-2"></i>
                                选择一个Rust知识点生成可视化图表：
                            </h5>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="topic-select" class="form-label">知识点</label>
                                    <select class="form-select" id="topic-select">
                                        <option value="">选择知识点...</option>
                                        <option value="ownership">所有权系统</option>
                                        <option value="borrowing">借用检查器</option>
                                        <option value="lifetimes">生命周期</option>
                                        <option value="traits">Trait系统</option>
                                        <option value="error-handling">错误处理</option>
                                        <option value="concurrency">并发编程</option>
                                        <option value="macros">宏系统</option>
                                        <option value="async">异步编程</option>
                                    </select>
                                    <div class="topic-description" id="topic-description">
                                        <small class="text-muted">选择一个知识点查看详细描述</small>
                                    </div>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label for="chart-type-select" class="form-label">图表类型</label>
                                    <select class="form-select" id="chart-type-select">
                                        <option value="流程图">流程图</option>
                                        <option value="类图">类图</option>
                                        <option value="状态图">状态图</option>
                                        <option value="关系图">关系图</option>
                                    </select>
                                    <div class="chart-type-description" id="chart-type-description">
                                        <small class="text-muted">选择图表类型查看详细描述</small>
                                    </div>
                                </div>
                            </div>
                            <button class="generate-button" id="generate-button">
                                <i class="fas fa-magic me-2"></i>
                                生成可视化图表
                            </button>
                        </div>
                        <div class="visualization-output" id="visualization-output">
                            <div class="text-center text-muted py-5">
                                <i class="fas fa-project-diagram fa-3x mb-3"></i>
                                <p>选择一个知识点和图表类型，然后点击"生成可视化图表"按钮</p>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-content" id="challenges-tab">
                    <div class="challenges-container">
                        <!-- 顶部导航栏 -->
                        <div class="top-nav">
                            <div class="nav-content">
                                <div class="back-btn" id="backBtn" style="display: none;" onclick="exitChallenge()">
                                    <i class="fas fa-arrow-left"></i> 返回关卡选择
                                </div>
                                <h1 class="nav-title">
                                    <i class="fas fa-gamepad me-2"></i>
                                    <span id="page-title">选择关卡</span>
                                </h1>
                            </div>
                        </div>

                        <!-- 关卡选择视图 -->
                        <div id="levelSelector" class="level-selector">
                            <div class="welcome-section text-center mb-4">
                                <h2 class="gradient-text">选择Rust学习主题</h2>
                                <p class="text-muted">通过代码关卡深入学习Rust核心概念</p>
                            </div>

                            <div id="topicLevels" class="topics-grid">
                                <!-- 主题关卡将通过JavaScript动态加载 -->
                            </div>
                        </div>

                        <!-- 挑战游戏视图 -->
                        <div id="challengeView" class="challenge-view" style="display: none;">
                            <div class="challenge-header">
                                <h3 id="challengeTitle" class="mb-3">
                                    <i class="fas fa-code me-2"></i>
                                    正在挑战
                                </h3>
                            </div>

                            <div class="challenge-content">
                                <!-- 左侧：关卡进度 -->
                                <div class="progress-sidebar">
                                    <div class="progress-card">
                                        <h5 class="progress-title">
                                            <i class="fas fa-trophy me-2"></i>
                                            关卡进度
                                        </h5>
                                        <div class="progress-stats">
                                            <div class="stat-item">
                                                <span class="stat-label">当前关卡</span>
                                                <span class="stat-value" id="currentLevelNum">1</span>
                                            </div>
                                            <div class="stat-item">
                                                <span class="stat-label">总关卡</span>
                                                <span class="stat-value" id="totalLevels">5</span>
                                            </div>
                                            <div class="stat-item">
                                                <span class="stat-label">完成率</span>
                                                <span class="stat-value" id="completionRate">0%</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- 右侧：挑战内容 -->
                                <div class="challenge-main">
                                    <div class="challenge-instructions">
                                        <h5>
                                            <i class="fas fa-lightbulb me-2"></i>
                                            任务说明
                                        </h5>
                                        <div id="challengeInstructions" class="instructions-content">
                                            <!-- 挑战说明将通过JavaScript动态更新 -->
                                        </div>
                                    </div>

                                    <div class="code-workspace">
                                        <h5>
                                            <i class="fas fa-code me-2"></i>
                                            代码工作区
                                        </h5>
                                        <div class="code-container">
                                            <div class="code-template" id="codeTemplate">
                                                <!-- 代码模板将通过JavaScript动态生成 -->
                                            </div>
                                        </div>
                                    </div>

                                    <div class="fragment-workspace">
                                        <h5>
                                            <i class="fas fa-puzzle-piece me-2"></i>
                                            代码片段
                                        </h5>
                                        <div class="fragments-container" id="fragmentList">
                                            <!-- 代码片段将通过JavaScript动态生成 -->
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="challenge-controls">
                                <button class="btn btn-secondary" onclick="resetChallenge()">
                                    <i class="fas fa-undo me-2"></i>
                                    重置关卡
                                </button>
                                <button class="btn btn-primary btn-check" onclick="checkAnswer()">
                                    <i class="fas fa-check me-2"></i>
                                    检查答案
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-core.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/mermaid@10.6.1/dist/mermaid.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
    <script>
        // Mermaid 10.x initialization - use minimal config to avoid conflicts
        // Detailed initialization is now handled in app.js
        if (typeof mermaid !== 'undefined') {
            // Let app.js handle the full initialization
            console.log('Mermaid library detected, will be initialized in app.js');
        }
    </script>
    <script src="{{ url_for('static', filename='js/app.js') }}"></script>
</body>
</html>